// pages/order_detail/order_detail.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        defaultAddress: {
            name: '张大仙',
            phone: '15665597078',
            address: '安徽省合肥市蜀山区西湖国际广场D座910皮诺客科技有限公司',

        },
        goods: {
            store: '豆豆小仙',
            list: [
                {
                    id: '0',
                    img: '/img/news.png',
                    goods_name: '春夏最新款时尚性感女士碎花雪纺衫',
                    color: '蓝色',
                    size: 'L',
                    price: '89.00',
                    count: 1,
                },
                {
                    id: '0',
                    img: '/img/news.png',
                    goods_name: '春夏最新款时尚性感女士碎花雪纺衫',
                    color: '蓝色',
                    size: 'L',
                    price: '89.00',
                    count: 1,
                }
            ],
        },
        freight: '0.00',
        isHasCoupon: false,
        coupon: '',
        totalPrice: '89.00',
        orderMessage:{
            number:'123456789',
            payType:'微信支付',
            order_time:'2018-01-16 14:01:34',
            send_time:'2018-01-17 14:01:34',
            post_type:'韵达快递'
        }
    },
    // 获取formid
    getFormId: function (e) {
      var formid = e.detail.formId;
      wx.request({
        url: app.siteInfo.siteroot + 'saveformid',
        method: "post",
        data: {
          uid: app.siteInfo.uid,
          formid: formid
        },
        success: function (res) {

        }
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var that = this;
      var id = options.id;
      if(id){
        that.setData({
          id:id
        })
      }else{
        wx.showToast({
          title: '订单不存在',
          image: '/img/fail.png',
          duration: 1500
        })
        wx.navigateTo({
          url: '/pages/order_list/order_list',
        })
      }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      var that = this;
      var id = that.data.id;
      if(!id){
        wx.showToast({
          title: '订单不存在',
          image: '/img/fail.png',
          duration: 1500
        })
        wx.navigateTo({
          url: '/pages/order_list/order_list',
        })
      }else{
        wx.request({
          url: app.siteInfo.shoppath +'orderdetail',
          method:"post",
          data:{
            orderid:id,
            uid: app.siteInfo.uid,
            pid: app.siteInfo.pid,
            com_part_id: app.siteInfo.com_part_id,
          },
          success:function(res){
            that.setData({
              orderinfo:res.data.list
            })
            if (res.data){
              if (res.data.cpid > 0) {
                that.setData({
                  isHasCoupon: true
                })
              }
            }
          }
        })
      }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
  onShareAppMessage: function () {
    wx.request({
      url: app.siteInfo.siteroot + 'relay',
      method: "post",
      data: {
        uid: app.siteInfo.uid,
        pid: app.siteInfo.pid,
        replaysource: "index"
      },
      success: function (res) { }
    })
    return {
      title: app.siteInfo.sharetitle,
      path: "/pages/index/index?share_card_id=" + app.siteInfo.pid + "&shareid=" + app.siteInfo.uid,
      success: function (a) {
        wx.request({
          url: app.siteInfo.siteroot + 'relay',
          method: "post",
          data: {
            uid: app.siteInfo.uid,
            pid: app.siteInfo.pid
          },
          success: function (res) { }
        })
      },
      fail: function (a) { }
    };
  }
})